<template>
  <base-breadcrumb :breadcrumb="!isAudit">
    <a-form-model
      :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
      :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }"
      :model="form"
      ref="ruleForm"
      :rules="rules"
    >
      <a-card>
        <title-name v-if="type == 'add'" title="新增设计资源考察"></title-name>
        <title-name v-if="type == 'edit'" title="编辑设计资源考察"></title-name>
        <title-name v-if="type == 'view' || type == 'approve'" title="查看设计资源考察"></title-name>

        <a-tabs ref="tabs" :activeKey="nextSteps" @change="callback">
          <a-tab-pane key="1" tab="基本信息">
            <a-row>
              <a-col :md="8" :sm="8">
                <a-form-model-item
                  label="考察资源名称"
                  :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                  :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }"
                  prop="name"
                >
                  <BaseInput
                    :disabled="type == 'view' || type == 'approve'"
                    v-model="form.name"
                    placeholder="请输入"
                  ></BaseInput>
                </a-form-model-item>
              </a-col>
              <a-col :md="8" :sm="8" v-if="type != 'view' && type != 'approve'">
                <a-button style="margin-left: 30px" type="primary" @click="openModal">选择</a-button
                ><span>(从推荐设计资源中选择)</span>
              </a-col>
            </a-row>
            <a-row>
              <a-col :md="8" :sm="8">
                <a-form-model-item
                  label="考察类型"
                  :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                  :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }"
                  prop="surveyTypeId"
                >
                  <a-select
                    :disabled="type == 'view' || type == 'approve'"
                    v-model="form.surveyTypeId"
                    placeholder="请选择"
                    @change="changeType"
                  >
                    <a-select-option v-for="item in typeList" :key="item.id" :value="item.id">
                      {{ item.name }}</a-select-option
                    >
                  </a-select>
                </a-form-model-item>
              </a-col>
              <a-col :md="8" :sm="8">
                <a-form-model-item
                  label="考察评级"
                  :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                  :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }"
                  prop="surveyLevelId"
                >
                  <a-select
                    :disabled="type == 'view' || type == 'approve'"
                    placeholder="请选择"
                    v-model="form.surveyLevelId"
                  >
                    <a-select-option v-for="item in recommendLevelOption" :key="item.id" :value="item.id">{{
                      item.name
                    }}</a-select-option>
                  </a-select>
                </a-form-model-item>
              </a-col>
              <!-- <a-col :md="8" :sm="8">
                <a-form-model-item label="考察分公司" prop="branchComId">
                  <a-select
                    @focus="changeCompany"
                    :getPopupContainer="getPopupContainer"
                    :disabled="type == 'view' || type == 'approve'"
                    v-model="form.branchComId"
                  >
                    <a-spin v-if="loading" slot="notFoundContent" size="small" />
                    <a-select-option v-for="item in companyLists" :key="item.id" :value="item.id"
                      >{{ item.name }}
                    </a-select-option>
                  </a-select>
                </a-form-model-item>
              </a-col> -->
              <a-col :md="8" :sm="8">
                <a-form-model-item label="考察分公司"
                              :labelCol="{lg: {span: 6}, sm: {span:6}}"
                              :wrapperCol="{lg: {span: 18}, sm: {span: 18} }" prop="branchComId" >
                  <SelectSubCompany   :disabled="type != 'add' && type != 'edit'" :getPopupContainer="getPopupContainer" :autoSelected='false' placeholder="请选择" v-model="form.branchComId" @change="changeCompany" ></SelectSubCompany>
                </a-form-model-item>
              </a-col>
              <a-col :md="8" :sm="8">
                <a-form-model-item
                  label="考察时间"
                  :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                  :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }"
                  prop="surveyDate"
                >
                  <!-- <BaseInput v-model="form.createTime" disabled placeholder="请输入"/> -->
                  <a-date-picker
                    :disabled="type == 'view' || type == 'approve'"
                    @change="changeTime"
                    v-model="form.surveyDate"
                  ></a-date-picker>
                </a-form-model-item>
              </a-col>
              <a-col :md="8" :sm="8">
                <a-form-model-item
                  label="创建人"
                  :labelCol="{ lg: { span: 2 }, sm: { span: 2 } }"
                  :wrapperCol="{ lg: { span: 22 }, sm: { span: 22 } }"
                  prop="createName"
                >
                  <BaseInput v-model="form.createName" disabled placeholder="请输入" />
                </a-form-model-item>
              </a-col>
              <a-col :md="8" :sm="8">
                <a-form-model-item
                  label="创建时间"
                  :labelCol="{ lg: { span: 2 }, sm: { span: 2 } }"
                  :wrapperCol="{ lg: { span: 22 }, sm: { span: 22 } }"
                  prop="createTime"
                >
                  <BaseInput v-model="form.createTime" disabled placeholder="请输入" />
                </a-form-model-item>
              </a-col>
            </a-row>
            <title-name title="考察小组"></title-name>
            <div>
              <a-row>
                <div v-if="type !== 'view' && type !== 'approve'" class="table-operator">
                  <a-row>
                    <a-col :md="24" :sm="24">
                      <a-button type="primary" @click="goAdd()">新增小组成员</a-button>
                      <a-button type="info" @click="goDel()">删除</a-button>
                    </a-col>
                  </a-row>
                </div>
                <a-table
                  :columns="columns2"
                  :rowKey="(record) => record.employeeId || record.id"
                  :rowSelection="groupRowSelection"
                  :data-source="memberList"
                >
                  <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
                  <span slot="post" slot-scope="text">
                    <ellipsis :length="20" tooltip>{{ text }}</ellipsis>
                  </span>
                  <template slot="leader" slot-scope="text, record">
                    <span v-if="record.leader">{{ ['组长', '成员'][record.leader - 1] }}</span>
                  </template>
                  <span slot="action" slot-scope="text, record, index">
                    <template>
                      <a v-if="type != 'view' && type != 'approve'" @click="handleEdit(record, index)">编辑</a>
                    </template>
                  </span>
                </a-table>
              </a-row>
            </div>

            <a-col :md="24" :sm="24" style="margin-top: 40px">
              <a-form-model-item
                label="考察小组意见"
                :labelCol="{ lg: { span: 2 }, sm: { span: 2 } }"
                :wrapperCol="{ lg: { span: 22 }, sm: { span: 22 } }"
                prop="opinion"
              >
                <BaseTextarea
                  type="textarea"
                  :disabled="type == 'view' || type == 'approve'"
                  v-model="form.opinion"
                  placeholder="请输入"
                />
              </a-form-model-item>
            </a-col>
            <!-- <div style="float:right;margin:10px"> -->
            <a-button
              style="float: right; margin-top: 50px; margin-right: 10px; margin-bottom: 20px"
              @click="nextStep()"
              type="primary"
              >下一步</a-button
            >
          </a-tab-pane>

          <a-tab-pane key="2" tab="考察信息">
            <company
              :resList="resList"
              ref="detailRef"
              :companyDetList="companyDetList"
              @submitForm="submimtFormCompany"
              @saveDraft="saveCompany"
              @submitCompany="getCompany"
              @validChanged="handleValidChanged"
              v-if="types == '设计单位'"
              v-on="$listeners"
            ></company>
            <expert
              :resList="resList"
              ref="detailRef"
              :expertList="expertList"
              @submitForm="submimtFormExpert"
              @saveDraft="saveExpert"
              @submitExpert="getExpert"
              @validChanged="handleValidChanged"
              v-if="types == '设计专家'"
              v-on="$listeners"
            ></expert>
            <overcompany
              :resList="resList"
              ref="detailRef"
              :companyDetList="companyDetList"
              @submitForm="submimtFormOverCompany"
              @saveDraft="saveOverCompany"
              @submitOverseasCompany="getOverseasCom"
              @validChanged="handleValidChanged"
              v-if="types == '海外设计单位'"
              v-on="$listeners"
            ></overcompany>
            <overexpert
              :resList="resList"
              ref="detailRef"
              :expertList="expertList"
              @submitForm="submimtFormOverExpert"
              @saveDraft="saveOverExpert"
              @submitOverseasExpert="getOverseasExpert"
              @validChanged="handleValidChanged"
              v-if="types == '海外设计专家'"
              v-on="$listeners"
            ></overexpert>
          </a-tab-pane>

          <a-tab-pane key="3" tab="附件上传">
            <title-name title="附件上传"></title-name>
            <u-table
              :uploadArrys="fileArrysDataList"
              :businessCode="businessCode"
              :listUrl="id ? listUrl : ''"
              :isShow="type != 'view' && type != 'approve'"
              :uploadList="uploadList"
              :businessId="id"
              :deleteUrl="deleteUrl"
              :refreshAfterUpload="false"
              @fileArrysData="fileArrysData"
            ></u-table>
          </a-tab-pane>
        </a-tabs>
      </a-card>
      <div v-if="!isConsultation" style="display: flex; float: right" class="page-btn-right-top">
        <a-button class="ml12" v-if="type == 'add' || type == 'edit'" type="primary" @click="saveDraft('btn')"
          >保存草稿</a-button
        >
        <a-button
          class="ml12"
          v-if="type == 'add' || type == 'edit'"
          type="primary"
          @click="submitForm"
          :loading="loadings"
          >提交</a-button
        >
        <a-button class="ml12" type="primary" @click="goBack">关闭</a-button>
      </div>
    </a-form-model>

    <!-- 考察小组 -->
    <a-modal
      width="60%"
      :visible="visible"
      v-if="visible"
      title="新增考察小组成员"
      @cancel="handleCancel"
      @ok="handleOk"
    >
      <a-form-model ref="createModal" :model="formAdd" :rules="groupFormRules">
        <a-row>
          <a-col :md="12" :sm="12">
            <a-form-model-item
              label="考察人员"
              :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
              :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }"
              prop="employeeId"
            >
              <a-select
                show-search
                placeholder="请选择"
                :filter-option="filterOption"
                v-model="employee"
                labelInValue
                @select="changeMember"
                @search="getOrgUsers"
                @focus="getOrgUsers"
                @popupScroll="scrollMore"
              >
                <a-icon slot="suffixIcon" type="search" />
                <a-spin v-if="loading" slot="notFoundContent" size="small" />
                <a-select-option v-for="item in groupList" :key="item.id" :value="item.id">{{
                  item.name
                }}</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :md="12" :sm="12">
            <a-form-model-item
              label="职位"
              :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
              :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }"
            >
              <BaseInput disabled v-model="formAdd.post"></BaseInput>
            </a-form-model-item>
          </a-col>
          <a-col :md="12" :sm="12">
            <a-form-model-item
              label="人员类型"
              :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
              :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }"
              prop="leader"
            >
              <a-select v-model="formAdd.leader" placeholder="请选择">
                <a-select-option value="1">组长</a-select-option>
                <a-select-option value="2">成员</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-modal>

    <!-- 推荐设计资源选择 -->
    <a-modal
      width="1000px"
      :visible="selectVisible"
      title="选择推荐设计资源"
      @cancel="handleCancelSelect"
      @ok="handleOkSelect"
    >
      <a-form :model="searchQuery">
        <a-row>
          <a-col :md="12" :sm="12">
            <a-form-model-item
              label="推荐设计资源名称"
              :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
              :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }"
            >
              <BaseInput v-model="searchQuery.resName" placeholder="请输入" />
            </a-form-model-item>
          </a-col>
          <a-col :md="12" :sm="12">
            <a-form-model-item
              label="推荐类型"
              :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
              :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }"
            >
              <a-select allowClear v-model="searchQuery.resTypeId" placeholder="请输入">
                <a-select-option v-for="item in investigateTypes" :key="item.id" :value="item.id">{{
                  item.name
                }}</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :md="12" :sm="12">
            <a-form-model-item
              label="推荐单位"
              :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
              :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }"
            >
              <a-select allowClear v-model="searchQuery.recommendOrgId" placeholder="请选择">
                <a-select-option v-for="item in relCompanyList" :key="item.id" :value="item.id">{{
                  item.name
                }}</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :md="12" :sm="12">
            <div style="float: right">
              <a-button style="margin: 0 20px" type="primary" @click="getResourceList">搜索</a-button>
              <a-button @click="getReset">重置</a-button>
            </div>
          </a-col>
        </a-row>
      </a-form>
      <a-table :columns="columns1" :rowSelection="rowSelection" :data-source="tableData">
        <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
      </a-table>
        <pagination
          :total="total"
          v-model="searchQuery.pageNo"
          :pageSize.sync="searchQuery.pageSize"
          @change="handlePageChange"
          @showSizeChange="showSizeChange"
        ></pagination>
    </a-modal>
    <selectApprover :businessId="businessId"  :processConfig="setProcessConfig"></selectApprover>
  </base-breadcrumb>
</template>


<script>
import { getAttachment, getTypesLabel } from '@/api/commons'
import { STable, Ellipsis } from '@/components'
import AddGroup from '@/views/subcontractors/investigate/components/AddGroup'
import Company from './components/Company'
import Expert from './components/Expert'
import overcompany from './components/OverseasCompany'
import overexpert from './components/OverseasExpert'
import { getStaffAll } from '@/api/subassembly/TreeSelectOrganization'
import { themeChoose } from '@/mixin/mixin'
import Staff from '@/components/TreeSelectOrganization/staff'
import { getOrgUsers } from '@/api/commons'
import { editList } from '@/api/design/investigate/company'
import {
  addBasic,
  getBasic,
  editBasic,
  addGroup,
  editGroup,
  getGroup,
  deleteGroup,
  getAudit,
  getCompanyDetailsInvestigate,
  deleteSurvey,
  deleteProjectFile
} from '@/api/design/investigate/index'
import { getSurveyList, addList, editExpert } from '@/api/design/investigate/expert'
import { getStatisticsTotal, getDesignResourcesList, addDesignResources } from '@/api/design/parameter'
import { getList, getListTotal, getExportDetails,getCompanyDetails } from '@/api/design/resourceRecommend/basic'
import { getAllBranchCompany, getLabelTypes } from '@/api/commons'

import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import OrgStaffAsync from '@/components/TreeSelectOrganization/orgStaffAsync'
import { createValidTool } from '@/utils/regExpression'
import transfersVue from '@/views/materials/remaining/parameter/components/transfers/transfers.vue'

const columns = [
  {
    title: '序号',
    scopedSlots: { customRender: 'serial' },
  },
  {
    title: '推荐分包商名称',
    dataIndex: 'recommendSubcontractors',
  },
  {
    title: '推荐人',
    dataIndex: 'recommend',
  },
  {
    title: '分公司',
    dataIndex: 'branchCompany',
  },
  {
    title: '推荐项目',
    dataIndex: 'recommendProject',
  },
  {
    title: '合作事项',
    dataIndex: 'cooperation',
  },
  {
    title: '操作',
    dataIndex: 'action',
    scopedSlots: { customRender: 'action' },
  },
]
const columns1 = [
  {
    title: '序号',
    dataIndex: 'serial',
    width: 65,
    scopedSlots: { customRender: 'serial' },
  },
  {
    title: '推荐设计资源名称',
    dataIndex: 'resName',
  },
  {
    title: '推荐类型',
    dataIndex: 'resTypeName',
  },
  {
    title: '推荐评级',
    dataIndex: 'resLevelName',
  },
  {
    title: '推荐单位',
    dataIndex: 'recommendOrgName',
  },
  {
    title: '推荐人',
    dataIndex: 'recommendEmployeeName',
  },
]
const columns2 = [
  {
    title: '序号',
    dataIndex: 'serial',
    scopedSlots: { customRender: 'serial' },
  },
  {
    title: '姓名',
    dataIndex: 'employeeName',
  },
  {
    title: '职位',
    dataIndex: 'post',
    scopedSlots: { customRender: 'post' },
  },
  {
    title: '类别',
    dataIndex: 'leader',
    scopedSlots: { customRender: 'leader' },
  },
  {
    title: '操作',
    dataIndex: 'action',
    scopedSlots: { customRender: 'action' },
  },
]


// 数组创建时候的下标
var numbe = 0

export default {
  name:'a'+ Date.now(),
  mixins: [themeChoose],
  components: {
    STable,
    AddGroup,
    Company,
    Expert,
    overcompany,
    overexpert,
    Ellipsis,
    Staff,
    OrgStaffAsync,
    SelectSubCompany,
  },
  props: {
    text: String,
    // 是否作为审批详情
    isAudit: {
      type: Boolean,
      default: false
    },
    // 是否作为意见征询
    isConsultation: {
      type: Boolean,
      default: false
    }
  },

  data() {
    return {
      columns,
      columns1,
      columns2,
      loadings:false,  // 提交
      childValidInfo: createValidTool(), // 验证子组件信息
      editTargetIndex: null, // 考察小组人员，编辑目标在表格中的序号
      ifSaveDraft: null,
      // 查询参数
      queryParam: {},
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return getGroup(requestParameters).then((res) => {
          return res
        })
      },
      visible: false,
      selectVisible: false,
      tableData: [],
      isShow: false,
      nextSteps: '1',
      total: 0,
      pageNo: 1,
      pageSize: 10,
      totalPage: null, // 总条数
      childrenNode: 'staff',
      // 附件上传
      listUrl: '/cscec-project-business/design-survey/project-fileQuery',
      deleteUrl: '/cscec-project-business/design-survey/project-fileDelete',
      fileArrysDataList: [],
      businessCode: 'PM26',
      uploadArrys: [],
      uploadList: '/cscec-project-business/design-survey/fileUpload',
      reqMethod: 'post',
      searchQuery: {
        pageNo: 1,
        pageSize: 10,
        status: 2,
      },
      loading: false,
      formAdd: {},
      types: '',
      employee: undefined,
      expertList: {},
      companyList: [],
      companyLists: [],
      dataSource: [],
      typeList: [],
      recommendLevelOption: [],
      title: '',
      group: {},
      memberList: [],
      selectedRowKeys: [],
      investigateTypes: [], // 推荐类型
      fileList: [
        {
          uid: '-1',
          name: 'image.png',
          status: 'done',
          url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
        },
      ],
      headers: {
        authorization: 'authorization-text',
      },
      form: {
        createTime: null,
      },
      status: 'all',
      areaCode: '',
      basicList: {},
      editsurveyName:'',
      dataList: [],
      groupList: [],
      submitExpertList: {},
      companyDetList: {},
      designTypes: [],
      selectedRows: [],
      groupSelectedRowKeys: [],
      isFromRecommand:false, //是否选择了推荐的数据
      groupSelectedRows: [],
      planId: '',
      recommandDesignTypeName:'',
      recommandDesignTypeId:'',
      id: '',
      resList: {},
      hasClickDraft:false,//点击保存草稿 = true
      rules: {
        name: [{ required: true, message: '请输入/选择考察名称', trigger: 'change' }],
        surveyTypeId: [{ required: true, message: '请选择考察类型', trigger: 'change' }],
        surveyLevelId: [{ required: true, message: '请选择考察评级', trigger: 'change' }],
        branchComId: [{ required: true, message: '请选择考察分公司', trigger: 'change' }],
        surveyDate: [{ required: true, message: '请选择考察时间', trigger: 'change' }],
        opinion: [{ required: true, message: '请输入考察小组意见', trigger: 'blur' }],
      },
      ifReplace: null, // 是否替换小组成员
      groupFormRules: {
        employeeId: [{ required: true, message: '请选择考察人员', trigger: 'change' }],
        leader: [{ required: true, message: '请选择人员类型', trigger: 'change' }],
      },

      pageNumber:1,   // 调入人员分页
      pageSize1:20,    // 调入人员分页数量
      totalPages:0,    // 总页数
      totalSize1:0,    // 总数
       //获取流程配置值
      processConfig: null,
      //点击提交发送流程配置值
      setProcessConfig: null,
      businessId: null,

    }
  },
 async created() {
    this.form.createTime = this.getNowTime()
    this.type = this.$route.query.type
    this.form.createName = JSON.parse(sessionStorage.getItem('ycloud-user_info')).employee.name
    this.id = this.$route.query.id
    this.getTypesLabel()

    this.getBasic()
    this.getAllBranchCompany()
    this.initPage()
    //获取通过获取流程配置值
    this.processConfig = await this.$getConfigFn('design_resource_inspect')
  },
  mounted() {
    this.getTypes()
    this.getTypesLabel()
  },
  computed: {
    rowSelection() {
      return {
        type: 'radio',
        selectedRowKeys: this.selectedRowKeys,
        selectedRows: this.selectedRows, // 当前行所有数据
        onChange: this.onSelectChange,
        getCheckboxProps: record => ({
          props: {
          // 禁止选中
            disabled: record.isWarehousing=='0'?true:false,
          },
        }),
      }
    },
    groupRowSelection() {
      return {
        selectedRowKeys: this.groupSelectedRowKeys,
        selectedRows: this.groupSelectedRows, // 当前行所有数据
        onChange: this.onSelectChangeGroup,
        getCheckboxProps: record => ({
          props: {
            // 禁止选中
            disabled: (this.type=='view' || this.type=='approve')?true:false,
          },
        }),
      }
    },
    relCompanyList() {
      // 去重处理
      const map = {}
      const result = []
      this.companyLists.forEach((item) => {
        if (!map[item.id]) {
          result.push(item)
          map[item.id] = true
        }
      })
      return result
    },
  },
  methods: {
    handleValidChanged(data) {
      this.childValidInfo.update(data)
    },
    /**
     * 初始化页面的一些操作
     */
    initPage() {
      if (this.type === 'view') {
        // 查看时，隐藏操作列
        const index = this.columns2.findIndex((item) => item.dataIndex === 'action')
        if (index > -1) {
          this.columns2.splice(index, 1)
        }
      }
    },
    getTypes() {
      getLabelTypes({ type: 14 }).then((res) => {
        this.investigateTypes = res.data
      })
    },
    getAllBranchCompany() {
      this.loading = true
      getAllBranchCompany({ tagCodes: ['CO'] }).then((res) => {
        this.companyList = res.data
        this.loading = false
      })
      getAllBranchCompany({ tagCodes: ['BC','CO'] }).then((res) => {
        this.companyLists = res.data
        this.loading = false
      })
    },
    filterOption(input, option) {
      return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
    },
    saveCompany(value) {
      editList(value).then((res) => {
        if (res.code == 200) {
          this.$message.success('保存草稿成功')
        }
      })
    },
    submimtFormCompany(value) {
      value.status = 'SUBMITTED'
      editList(value).then((res) => {
        this.$router.push("/project/design/resource/investigate")
        if (res.code == 200) {
          this.$message.success('提交成功')
        }
      })
    },
    saveOverCompany(value) {
      editList(value).then((res) => {
        this.nextSteps = '3'
        if (res.code == 200) {
          this.$message.success('保存草稿成功')
        }
      })
    },
    submimtFormOverCompany(value) {
      value.status = 'SUBMITTED'
      editList(value).then((res) => {
        this.$router.push("/project/design/resource/investigate")
        if (res.code == 200) {
          this.$message.success('提交成功')
        }
      })
    },
    saveExpert(value) {
      this.submitExpertList = value
      editExpert(value).then((res) => {
        if (res.code == 200) {
          this.$message.success('保存草稿成功')
        }
      })

    },
    submimtFormExpert(value) {
      value.status = 'SUBMITTED'
      this.submitExpertList = value
      editExpert(value).then((res) => {
        this.$router.push("/project/design/resource/investigate")
        if (res.code == 200) {
          this.$message.success('提交成功')
        }
      })
    },
    saveOverExpert(value) {
      editExpert(value).then((res) => {
        if (res.code == 200) {
          this.$message.success('保存草稿成功')
        }
      })
    },
    submimtFormOverExpert(value) {
      value.status = 'SUBMITTED'
      editExpert(value).then((res) => {
        this.$router.push("/project/design/resource/investigate")
        if (res.code == 200) {
          this.$message.success('提交成功')
        }
      })
    },
    openModal() {
      this.selectedRowKeys = []
      this.selectedRows = []
      this.getResourceList()
      this.selectVisible = true
    },
    submitForm() {
      this.setProcessConfig = null;
      this.businessId = null;
      // 验证子组件是否有内容填写错误
      const validInfo = this.childValidInfo.validate()
      if (!validInfo.valid) {
        this.$message.warn(validInfo.message)
        return
      }
      // 验证考察成员列表是否存在组长
      const hasLeader = this.memberList.some((item) => {
        if (item.leader === '1') {
          return true
        }
      })
      if (this.nextSteps == '1') {
        if (hasLeader) {
          if (this.id) {
            this.form.status = 'SUBMITTED'
            this.$refs.ruleForm.validate((err, value) => {
              if (err) {
                this.loadings = true
                getDesignResourcesList({pageNo:1,pageSize:2000}).then(res=>{
                  this.loadings = false
                  let data = []
                  data = res.data.filter(item=>item.name==this.form.name)
                  if(data.length>=1){
                    this.$message.error("此设计资源已入设计资源台账，不能重复提交")
                    return false
                  }else{
                    editBasic({
                      ...this.form,
                      memberList: this.memberList,
                    }).then((res) => {
                      if (res.code == 200|| res.data.code == 200) {
                        // this.$message.success('提交成功1')
                        // this.businessId = this.id;
                        // this.setProcessConfig = this.processConfig;
                        this.$message.success('提交成功')
                        this.$multiTab.close(this.$route.fullpath)
                      }
                    })
                  }
                })
              } else {
                this.$message.warning("请填写完所有必填项信息")
              }
            })
          } else {
            this.form.status = 'SUBMITTED'
            this.$refs.ruleForm.validate((err, value) => {
              if (err) {
                this.loadings = true
                this.submitApprovalConfirm(this.processConfig,(flag)=>{
                  if(!flag) {
                    this.loadings = false
                    return
                  }
                getDesignResourcesList({pageNo:1,pageSize:2000}).then(res=>{
                  this.loadings = false
                  let data = []
                  data = res.data.filter(item=>item.name==this.form.name)
                  if(data.length>=1){
                    this.$message.error("此设计资源已入设计资源台账，不能重复提交")
                    return false
                  }else{
                    addBasic({
                      ...this.form,
                      memberList: this.memberList,
                    }).then((res) => {
                      if (res.code == 200|| res.data.code == 200) {
                        this.$message.success('提交成功')
                        this.businessId = res.data.id;
                        this.setProcessConfig = this.processConfig;
                      }
                    })
                  }
                })
                })
              } else {
                this.$message.warning("请填写完所有必填项信息")
              }
            })
          }
        }else{
          this.$message.error('请先添加小组组长')
        }
      } else if (this.nextSteps == '2') {
        if (
          (this.$refs.detailRef.companyDetList && this.$refs.detailRef.companyDetList.resTypeName == '设计单位') ||
          (this.$refs.detailRef.companyDetList && this.$refs.detailRef.companyDetList.resTypeName == '海外设计单位')
        ) {
          let obj = this.$refs.detailRef.companyDetList
          if (obj.achievementsDTO) {
            obj.achievementsDTO.forEach((item) => {
              item.id = null
            })
          }
          if (obj.certifications) {
            obj.certifications.forEach((item) => {
              item.id = null
            })
          }
          if (obj.companyManagements) {
            obj.companyManagements.forEach((item) => {
              item.id = null
            })
          }
          obj.surveyId = this.id
          obj.status = 'SUBMITTED'
          // surveyName
          this.loadings = true
            getDesignResourcesList({pageNo:1,pageSize:2000}).then(res=>{
              this.loadings = false
              let data = []
              data = res.data.filter(item=>item.name==obj.surveyName)
              if(data.length>=1){
                this.$message.error("此设计资源已入设计资源台账，不能重复提交")
                return false
              }else{
                editList(obj).then((res) => {
                  if (res.code == 200|| res.data.code == 200) {
                    // this.$message.success('提交成功3')
                    // this.businessId = this.id;
                    // this.setProcessConfig = this.processConfig;
                    this.$message.success('提交成功')
                    this.$multiTab.close(this.$route.fullpath)
                  }
                })
              }
            })
        } else if (
          (this.$refs.detailRef.expertList && this.$refs.detailRef.expertList.resTypeName == '设计专家') ||
          (this.$refs.detailRef.expertList && this.$refs.detailRef.expertList.resTypeName == '海外设计专家')
        ) {
          let obj1 = this.$refs.detailRef.expertList
          if (obj1.achievementsDTO) {
            obj1.achievementsDTO.forEach((item) => {
              if (item.id) {
                item.id = null
              }
            })
          }
          obj1.surveyId = this.id
          obj1.status = 'SUBMITTED'
          this.$refs.ruleForm.validate((err, value) => {
            if (err) {
              this.loadings = true
              this.submitApprovalConfirm(this.processConfig, (flag)=>{
                if(!flag) {
                  this.loadings = false
                  return
                }
              getDesignResourcesList({pageNo:1,pageSize:2000}).then(res=>{
                this.loadings = false
                let data = []
                data = res.data.filter(item=>item.name==obj1.surveyName)
                if(data.length>=1){
                  this.$message.error("此设计资源已入设计资源台账，不能重复提交")
                  return false
                }else{
                  editExpert(obj1).then((res) => {
                    if (res.code == 200|| res.data.code == 200) {
                      this.businessId = this.id
                      this.setProcessConfig = this.processConfig;
                    }
                  })
                }
              })
              })
            } else {
              this.$message.warning("请填写完所有必填项信息")
            }
          })
        }
      } else if (this.nextSteps == '3') {
        this.submitApprovalConfirm(this.processConfig, (flag)=>{
          if(!flag) {
            this.loadings = false
            return
          }
        if (this.id) {
          this.$refs.ruleForm.validate((err, value) => {
            if (err) {
              this.loadings = true
              getAudit({ id: this.id }).then((res) => {
                this.loadings = false
                this.$message.success('提交成功')
                  this.businessId = this.id
                  this.setProcessConfig = this.processConfig;
              })
            } else {
              this.$message.warning("请填写完所有必填项信息")
            }
          })
        }
        })
      } else {
        this.$message.success('提交成功')
        this.$router.push("/project/design/resource/investigate")
      }
    },
    saveDraft(type) {
      // 验证子组件是否有内容填写错误
      const validInfo = this.childValidInfo.validate()
      if (!validInfo.valid) {
        this.$message.warn(validInfo.message)
        return
      }
      this.ifSaveDraft = 1
      if (this.nextSteps == '1') {
        if (this.id) {
          editBasic({
            ...this.form,
            memberList: this.memberList,
            id: this.id,
          }).then((res) => {
            if (res.code == 200|| res.data.code == 200) {
              this.id = res.data.id
              this.$message.success('保存草稿成功')
              if(type==='btn'){
                this.hasClickDraft = true
              }
            }
          })
        } else {
          this.form.auditStatus = 'DRAFT'
          addBasic({
            ...this.form,
            memberList: this.memberList,
          }).then((res) => {
            if (res.code == 200|| res.data.code == 200) {
              this.id = res.data.id
              this.$message.success('保存草稿成功')
              if(type==='btn'){
                this.hasClickDraft = true
              }
            }
          })
        }
      } else if (this.nextSteps == '2') {
        if (
          (this.$refs.detailRef.companyDetList && this.$refs.detailRef.companyDetList.resTypeName == '设计单位') ||
          (this.$refs.detailRef.companyDetList && this.$refs.detailRef.companyDetList.resTypeName == '海外设计单位')
        ) {
          let obj = this.$refs.detailRef.companyDetList
          if (obj.achievementsDTO) {
            obj.achievementsDTO.forEach((item) => {
              item.id = null
            })
          }
          if (obj.certifications) {
            obj.certifications.forEach((item) => {
              item.id = null
            })
          }
          if (obj.companyManagements) {
            obj.companyManagements.forEach((item) => {
              item.id = null
            })
          }
          obj.surveyId = this.id
          editList(obj).then((res) => {
            if(res.code===200 || res.data.code == 200){
              this.$message.success('保存草稿成功')
              if(type==='btn'){
                this.hasClickDraft = true
              }
            }
            // this.$multiTab.close(this.$route.fullpath)
          })
        } else if (
          (this.$refs.detailRef.expertList && this.$refs.detailRef.expertList.resTypeName == '设计专家') ||
          (this.$refs.detailRef.expertList && this.$refs.detailRef.expertList.resTypeName == '海外设计专家')
        ) {
          let obj1 = this.$refs.detailRef.expertList
          if (obj1.achievementsDTO) {
            obj1.achievementsDTO.forEach((item) => {
              if (item.id) {
                item.id = null
              }
            })
          }
          obj1.surveyId = this.id
          this.$refs.ruleForm.validate((err, value) => {
            if (err) {
              editExpert(obj1).then(res => {
                if(res.code===200|| res.data.code == 200){
                  this.$message.success('保存草稿成功')
                  if(type==='btn'){
                    this.hasClickDraft = true
                  }
                }
                // this.$multiTab.close(this.$route.fullpath)
              })
            }
          })
        } else {
          this.$message.success('保存草稿成功')
        }
      } else {
        this.$message.success('保存草稿成功')
        if(type==='btn'){
            this.hasClickDraft = true
        }
      }
    },
    goBack() {
      let _this = this
      if (this.type !== 'add' && this.type !== 'approve') {
        _this.$multiTab.close(_this.$route.fullpath)
      } else if (this.type == 'approve') {
        window.close()
      } else if (this.hasClickDraft) {
        _this.$multiTab.close(_this.$route.fullpath)
      } else {
        if (this.id) {
          this.$confirm({
            title: '警告提醒！',
            content: '未进行保存，将删除当前数据，请问是否确认退出？',
            okType: 'danger',
            onOk() {
              let num = 0
              if(_this.fileArrysDataList.length===0){
                  deleteSurvey({ id: _this.id }).then((res) => {
                        _this.$message.success('删除成功')
                        _this.$multiTab.close(_this.$route.fullpath)
                  })
              }else{
                _this.fileArrysDataList.map(item=>{
                    deleteProjectFile({businessId:_this.id,code:_this.businessCode,commonFileId:item.commonId}).then(res=>{
                      num++
                      if(num===_this.fileArrysDataList.length){
                        deleteSurvey({ id: _this.id }).then((res) => {
                          _this.$message.success('删除成功')
                          _this.$multiTab.close(_this.$route.fullpath)
                        })
                      }
                    })
                })
              }
            },
          })
        } else {
          this.$confirm({
            title: '警告提醒！',
            content: '未进行保存，将删除当前数据，请问是否确认退出？',
            okType: 'danger',
            onOk() {
              _this.$message.success('删除成功')
              _this.$multiTab.close(_this.$route.fullpath)
            },
          })
        }
      }
    },
    getPopupContainer(triggerNode) {
      return triggerNode.parentNode
    },
    fileArrysData(val) {
      // this.fileArrysDataList = this.fileArrysDataList.concat(val)
      this.fileArrysDataList = val
    },
    handleSelect(record) {
      this.$message.success('已选择')
      this.form.name = record.resName
      this.form.nameId = record.nameId
    },
    handleCancelSelect() {
      this.selectVisible = false
    },
    getResourceList() {
      const params = {
        ...this.searchQuery,
        recommendOrgId: this.searchQuery.recommendOrgId || void 0,
      }
      getList(params).then((res) => {
        this.tableData = res.data
        this.total = res.totalSize
      })
    },
    handlePageChange(pageNo, pageSize) {
      this.searchQuery.pageNo = pageNo
      this.searchQuery.pageSize = pageSize
      this.getResourceList()
    },
    showSizeChange(pageNo, pageSize) {
      this.searchQuery.pageNo = pageNo
      this.searchQuery.pageSize = pageSize
      this.getResourceList()
    },
    getBasic() {
      if (this.id) {
        getBasic({ id: this.id }).then((res) => {
          this.form = res.data
          this.$set(this.form, 'oldsurveyTypeId', res.data.surveyTypeId)
          if (res.data.memberList) {
            res.data.memberList.forEach((item) => {
              for (let i = 5; i < 1000; i++) {
                item.id = i
              }
            })
            this.memberList = res.data.memberList
          }
        })
      }
    },
    getTypesLabel() {
      // 考察类型
      getTypesLabel({ type: '14' }).then((res) => {
        this.typeList = res.data
      })
      // 评级
      getTypesLabel({ type: '13' }).then((res) => {
        this.recommendLevelOption = res.data
      })
      // 职称
      getTypesLabel({ type: '15' }).then((res) => {
        this.titleList = res.data
      })
      // 学历
      getTypesLabel({ type: '16' }).then((res) => {
        this.educationList = res.data
      })
    },
    getCompany(value) {
      if (this.type === 'view' || this.type === 'approve') {
        this.nextSteps = '3'
        return
      }
      editList(value).then((res) => {
        this.nextSteps = '3'
        if (res.code == 200) {
          this.$message.success('保存成功')
          this.nextSteps = '3'
        }
      })
    },
    getExpert(value) {
      console.log(value)
      this.submitExpertList = value
      if (this.type === 'view' || this.type === 'approve') {
        this.nextSteps = '3'
        return
      }
      editExpert(value).then((res) => {
        this.nextSteps = '3'
        if (res.code === 200) {
          this.$message.success('保存成功')
          this.nextSteps = '3'
        }
      })
    },
    getOverseasCom(value) {
      if (this.type === 'view' || this.type === 'approve') {
        this.nextSteps = '3'
        return
      }
      editList(value).then((res) => {
        this.nextSteps = '3'
        if (res.code == 200) {
          this.$message.success('保存成功')
          this.nextSteps = '3'
        }
      })
    },
    getOverseasExpert(value) {
      if (this.type === 'view' || this.type === 'approve') {
        this.nextSteps = '3'
        return
      }
      editExpert(value).then((res) => {
        this.nextSteps = '3'
        if (res.code == '200') {
          this.$message.success('保存成功')
          this.nextSteps = '3'
        }
      })
    },
    changeTime(value, dateString) {
      this.form.surveyDate = dateString
    },
    // 下拉滚动加载
    scrollMore(e) {
      const { target } = e
      var total = target.scrollTop + target.offsetHeight
      var scrollHeight = target.scrollHeight

      // this.pageNo是当前页 this.totalPage是总页数
      if (total >= scrollHeight - 1 && total < scrollHeight + 1 && this.pageNumber <= this.totalPages ) {
        this.pageNumber = this.pageNumber + 1
        this.getOrgUsers() // 调用api方法
      }
    },
    getOrgUsers(val) {
      getOrgUsers({key:val?val:'',pageNumber:this.pageNumber,pageSize:this.pageSize1}).then((res) => {
        if(res.data){
          let data = []
          res.data && res.data.forEach(item => {
            if (!this.groupList.filter(itemc => item.id == itemc.id).length) {
              data.push(item)
            }
          })
          this.groupList  = this.groupList.concat(data)
        }
        this.totalPages = res.totalPages
        this.totalSize1 = res.totalSize
      })
    },
    goDel() {
      if(this.groupSelectedRowKeys.length == 0){
        this.$message.error("请先选择需要删除的成员！")
        return
      }else{
        let _this = this
        _this.$confirm({
          title: '警告提醒！',
          content: '确定删除所选成员？',
          okType: 'danger',
          onOk() {
            _this.memberList = _this.memberList.filter((item) => {
              return !_this.groupSelectedRowKeys.includes(item.employeeId)
            })
            _this.groupSelectedRows = []
            _this.groupSelectedRowKeys = []
            _this.$message.success('删除成功')
          },
          onCancel() {
            console.log("取消删除")
          },
        })
      }
    },
    choice(type) {
      this.visible = true
    },

    changeType(value) {
      if (this.id) {
        let _this = this
        _this.$confirm({
          title: '警告提醒！',
          content: '如果切换，则已填写的考察信息将不再保存',
          okType: 'danger',
          onOk() {
            _this.childValidInfo = _this.$options.data().childValidInfo // 还原子组件验证状态信息
            return false
          },
          onCancel() {
            _this.$set(_this.form, 'surveyTypeId', _this.form.oldsurveyTypeId)
          },
        })
        // return false
      }
    },
    getReset() {
      this.searchQuery = this.$options.data().searchQuery
      this.getResourceList()
    },
    goAdd() {
      this.editTargetIndex = null // 重置序号
      this.ifReplace = null // 重置编辑标识
      this.visible = true
      this.employee = undefined
      this.formAdd = {}
    },

    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    onSelectChangeGroup(selectedRowKeys, selectedRows) {
      this.groupSelectedRowKeys = selectedRowKeys
      this.groupSelectedRows = selectedRows
    },
    employeeNums(val) {
      this.employeeNum = val
    },
    changeCompany() {
    },
    getSurveyListReq(){
      let that = this;
      getSurveyList({ id: that.id }).then((res) => {
        that.expertList = res.data
        that.expertList.resTypeName = that.types
        that.expertList.surveyName = that.editsurveyName || that.form.name
        if (!that.expertList.achievementsDTO) {
          that.expertList.achievementsDTO = []
        }
        if(!that.expertList.maxEducationId){
          that.$set(that.expertList,'maxEducationName','')
          // 最高学历无placeholder
          that.$set(that.expertList,'maxEducationId',undefined)
        }
        // 职称无placeholder
        if(!that.expertList.jobTitleId){
          that.$set(that.expertList,'jobTitleId','')
        }
        that.getTypesLabel()
      })
    },
    getCompanyDetailsInvestigateReq(){
      let that = this;
      getCompanyDetailsInvestigate({ id: that.id }).then((res) => {
        that.companyDetList = res.data
        that.companyDetList.resTypeName = that.types
        that.companyDetList.surveyName = that.editsurveyName || that.form.name
        if (!that.companyDetList.achievementsDTO) {
          that.companyDetList.achievementsDTO = []
        }
        if(!that.companyDetList.natureOfEnterpriseId){
          that.$set(that.companyDetList,'natureOfEnterpriseId',undefined)
        }
        if (!that.companyDetList.companyManagements) {
          that.companyDetList.companyManagements = []
        }
        if (!that.companyDetList.certifications) {
          that.companyDetList.certifications = []
        }
        that.getTypesLabel()
      })
    },


    callback(key) {
      let that  = this;
      // 切换tab时重置表单验证
      if(that.$refs?.detailRef&&that.$refs?.detailRef.$refs){
        that.$refs.detailRef.$refs.validForm?.resetFields()
      }

      if (that.type != 'view' && that.type !='approve') {
        that.$refs.ruleForm.validate((valid) => {
          if (valid) {
            if(key == 2){
              let arr = []
              that.memberList.forEach((item) => {
                arr = that.memberList.filter((items) => items.leader == '1')
                item.id = null
              })
              if (arr.length == 0) {
                that.$message.error('请选择考察小组组长')
                return false
              } else if (arr.length > 1) {
                that.$message.error('只能选择一个考察小组组长')
                return false
              }
              that.form.memberList = that.memberList
              // 判断是新增还是编辑
              if (that.id) {//编辑
                that.form.id = that.id
                // 判断是自己选的还是从设计推荐资源选的
                if(that.isFromRecommand==true){ //从设计资源选择
                  if(that.recommandDesignTypeId!==that.form.surveyTypeId){ //如果是从设计资源推荐选择的，但是又修改了考察类型

                    that.form.memberList = that.memberList
                    editBasic(that.form).then((res) => {
                      if ( res.code == 200 ) {
                        that.nextSteps = key
                        that.types = res.data.surveyTypeName

                        if (that.types == '设计专家' || that.types == '海外设计专家') {
                          that.getSurveyListReq();
                        } else if (that.types == '设计单位' || that.types == '海外设计单位') {
                          that.getCompanyDetailsInvestigateReq()
                        }
                      }
                    })
                  }else{ //从设计资源选择的未修改考察类型
                    that.form.memberList = that.memberList
                    editBasic(that.form).then((res) => {
                      that.types = res.data.surveyTypeName
                      that.id = res.data.id
                      if (res.code == 200) {
                        that.nextSteps = key
                        that.editsurveyName=res.data.name
                        that.resList = res.data
                        if (res.data.surveyTypeName == '设计专家' || res.data.surveyTypeName == '海外设计专家') {
                          that.getSurveyListReq();
                        } else if (res.data.surveyTypeName == '设计单位' || res.data.surveyTypeName == '海外设计单位')
                        {
                          that.getCompanyDetailsInvestigateReq()
                        }
                      }
                    })
                  }
                }else if(that.isFromRecommand==false){ //自己填的数据

                  editBasic(that.form).then((res) => {
                    if ( res.code == 200 ) {
                      that.nextSteps = key
                      that.types = res.data.surveyTypeName

                      if (that.types == '设计专家' || that.types == '海外设计专家') {
                        that.getSurveyListReq();
                      } else if (that.types == '设计单位' || that.types == '海外设计单位') {
                        that.getCompanyDetailsInvestigateReq()
                      }
                    }
                  })
                }
              } else { //新增

                console.log("这是新增的实际考察")

                that.form.memberList = that.memberList
                // 判断是自己选的还是从设计推荐资源选的
                if(that.isFromRecommand==true){ //从设计资源选择
                  //如果是从设计资源推荐选择的，但是又修改了考察类型
                  if(that.recommandDesignTypeId!==that.form.surveyTypeId){
                    that.form.memberList = that.memberList
                    addBasic(that.form).then((res) => {
                      that.types = res.data.surveyTypeName
                      that.id = res.data.id
                      if (res.code == 200) {
                        that.nextSteps = key
                        that.resList = res.data
                        if (that.types == '设计专家' || that.types == '海外设计专家') {
                          that.getSurveyListReq();
                        } else if (that.types == '设计单位' || that.types == '海外设计单位') {
                          that.getCompanyDetailsInvestigateReq()
                        }
                      }
                    })
                  }else{ //从设计资源选择的未修改考察类型
                    that.form.memberList = that.memberList
                    addBasic(that.form).then((res) => {
                      that.types = res.data.surveyTypeName
                      that.id = res.data.id
                      if (res.code == 200) {
                        that.nextSteps = key
                        that.resList = res.data
                        if (res.data.surveyTypeName == '设计专家' || res.data.surveyTypeName == '海外设计专家') {
                          getExportDetails({ id: that.selectedRows[0].id }).then((res) => {
                            that.expertList = res.data
                            that.expertList.resTypeName = that.types
                            that.expertList.surveyName = that.editsurveyName || that.form.name
                            if (!that.expertList.achievementsDTO) {
                              that.expertList.achievementsDTO = []
                            }
                            that.getTypesLabel()
                          })
                        } else if (res.data.surveyTypeName == '设计单位' || res.data.surveyTypeName == '海外设计单位')
                        {
                          getCompanyDetails({ id: that.selectedRows[0].id }).then((res) => {
                            that.companyDetList = res.data
                            that.companyDetList.resTypeName = that.types
                            that.companyDetList.surveyName = that.editsurveyName || that.form.name
                            if (!that.companyDetList.achievementsDTO) {
                              that.companyDetList.achievementsDTO = []
                            }
                            if (!that.companyDetList.companyManagements) {
                              that.companyDetList.companyManagements = []
                            }
                            if (!that.companyDetList.certifications) {
                              that.companyDetList.certifications = []
                            }
                            that.getTypesLabel()
                          })
                        }
                      }
                    })
                  }
                }else if(that.isFromRecommand==false){ //自己填的数据
                  that.form.memberList = that.memberList
                  addBasic(that.form).then((res) => {
                    that.types = res.data.surveyTypeName
                    that.id = res.data.id
                    if (res.code == 200) {
                      that.nextSteps = key
                      that.resList = res.data
                      if (res.data.surveyTypeName == '设计专家' || res.data.surveyTypeName == '海外设计专家') {
                        that.getSurveyListReq();
                      } else if (res.data.surveyTypeName == '设计单位' || res.data.surveyTypeName == '海外设计单位')
                      {
                        that.getCompanyDetailsInvestigateReq()
                      }
                    }
                  })
                }
              }
            }
            else if(key ==1 && that.type != 'view' && that.type !='approve'){
              let result = that.$refs.detailRef.expertList || that.$refs.detailRef.companyDetList || {}
              if(result.companyManagements){
                result.companyManagements.forEach(item=>{
                  item.id=null
                })
              }
              if(result.certifications){
                result.certifications.forEach(item=>{
                  item.id=null
                })
              }
              if(result.achievementsDTO){
                result.achievementsDTO.forEach(item=>{
                  item.id=null
                })
              }
              result.surveyId=that.id

              if(result.resTypeName=='设计单位' || result.resTypeName=='海外设计单位' ){
                editList(result).then((res) => {
                  if (res.code == 200 || res.data.code == 200) {
                    that.nextSteps = key
                    that.$message.success('保存成功')
                  }
                })
              }else if(result.resTypeName=='设计专家' || result.resTypeName=='海外设计专家' ){
                editExpert(result).then((res) => {
                  if (res.code == 200 || res.data.code == 200) {
                    that.nextSteps = key
                    that.$message.success('保存成功')
                  }
                })
              }
            }

            else if(key==3){   //  从考察信息到附件上传
              let result = that.$refs.detailRef.expertList || that.$refs.detailRef.companyDetList || {}
              if(result.companyManagements){
                result.companyManagements.forEach(item=>{
                  item.id=null
                })
              }
              if(result.certifications){
                result.certifications.forEach(item=>{
                  item.id=null
                })
              }
              if(result.achievementsDTO){
                result.achievementsDTO.forEach(item=>{
                  item.id=null
                })
              }
              result.surveyId=that.id

              if(result.resTypeName=='设计单位' || result.resTypeName=='海外设计单位' ){
                editList(result).then((res) => {
                  if (res.code == 200 || res.data.code == 200) {
                    that.nextSteps = key
                    that.$message.success('保存成功')
                  }
                })
              }else if(result.resTypeName=='设计专家' || result.resTypeName=='海外设计专家' ){
                editExpert(result).then((res) => {
                  if (res.code == 200 || res.data.code == 200) {
                    that.nextSteps = key
                    that.$message.success('保存成功')
                  }
                })
              }
            }else{
              that.nextSteps = key
            }
          } else {
            this.$message.warning("请填写完所有必填项信息")
          }
        })

      } else {
        that.nextSteps = key // 查看页面时，直接跳转
        if (that.nextSteps == 2) {
          that.types = that.form.surveyTypeName
          if (that.form.surveyTypeName == '设计专家' || that.types == '海外设计专家') {
            getSurveyList({ id: that.id }).then((res) => {
              that.expertList = res.data
              if (!that.expertList.achievementsDTO) {
                that.expertList.achievementsDTO = []
              }
              that.getTypesLabel()
            })
          } else if (that.form.surveyTypeName == '设计单位' || that.form.surveyTypeName == '海外设计单位') {
            getCompanyDetailsInvestigate({ id: that.id }).then((res) => {
              that.companyDetList = res.data
              if (!that.companyDetList.achievementsDTO) {
                that.companyDetList.achievementsDTO = []
              }
              if (!that.companyDetList.companyManagements) {
                that.companyDetList.companyManagements = []
              }
              if (!that.companyDetList.certifications) {
                that.companyDetList.certifications = []
              }
              that.getTypesLabel()
            })
          }
        }
      }
    },
    // 下一步
    async nextStep() {
      let flag = true
      if (this.type !== 'view') {
        flag = await this.$refs.ruleForm.validate()
      }
      if (!flag) {
        this.$message.warning("请填写完所有必填项信息")
        return}
      let steps = this.nextSteps
      if (steps == '1') { //保存第一页
        if (!this.form.surveyTypeId) {
          this.$message.error('请选择考察类型')
          this.nextSteps = '1'
        } else {
          let arr = []
          this.memberList.forEach((item) => {
            arr = this.memberList.filter((items) => items.leader == '1')
            item.id = null
          })
          if (arr.length == 0) {
            this.$message.error('请选择考察小组组长')
            return false
          } else if (arr.length > 1) {
            this.$message.error('只能选择一个考察小组组长')
            return false
          } else {
            // 判断是编辑还是新增
            if (this.id) { //编辑
              this.form.id = this.id
              this.form.memberList = this.memberList
                // 判断是自己选的还是从设计推荐资源选的
                if(this.isFromRecommand==true){ //从设计资源选择
                    if(this.recommandDesignTypeId!==this.form.surveyTypeId){ //如果是从设计资源推荐选择的，但是又修改了考察类型
                        editBasic(this.form).then((res) => {
                          if ( res.code == 200 ) {
                            this.types = res.data.surveyTypeName
                            this.nextSteps='2'
                            if (this.types == '设计专家' || this.types == '海外设计专家') {
                              getSurveyList({ id: this.id }).then((res) => {
                                this.expertList = res.data
                                this.expertList.resTypeName = this.types
                                this.expertList.surveyName = this.editsurveyName || this.form.name
                                if (!this.expertList.achievementsDTO) {
                                  this.expertList.achievementsDTO = []
                                }
                                if(!this.expertList.maxEducationId){
                                  this.$set(this.expertList,'maxEducationName','')
                                  // 最高学历无placeholder
                                  this.$set(this.expertList,'maxEducationId',undefined)
                                }
                                // 职称无placeholder
                                if(!this.expertList.jobTitleId){
                                  this.$set(this.expertList,'jobTitleId','')
                                }
                                this.getTypesLabel()
                              })
                            } else if (this.types == '设计单位' || this.types == '海外设计单位') {
                              getCompanyDetailsInvestigate({ id: this.id }).then((res) => {
                                this.companyDetList = res.data
                                this.companyDetList.resTypeName = this.types
                                this.companyDetList.surveyName = this.editsurveyName || this.form.name
                                if (!this.companyDetList.achievementsDTO) {
                                  this.companyDetList.achievementsDTO = []
                                }
                                if(!this.companyDetList.natureOfEnterpriseId){
                                  this.$set(this.companyDetList,'natureOfEnterpriseId',undefined)
                                }
                                if (!this.companyDetList.companyManagements) {
                                  this.companyDetList.companyManagements = []
                                }
                                if (!this.companyDetList.certifications) {
                                  this.companyDetList.certifications = []
                                }
                                this.getTypesLabel()
                              })
                            }
                          }
                        })
                    }else{ //从设计资源选择的未修改考察类型
                      this.form.memberList = this.memberList
                      editBasic(this.form).then((res) => {
                        this.types = res.data.surveyTypeName
                        this.id = res.data.id
                        if (res.code == 200) {
                          this.resList = res.data
                          this.nextSteps='2'
                          if (res.data.surveyTypeName == '设计专家' || res.data.surveyTypeName == '海外设计专家') {
                            getExportDetails({ id: this.selectedRows[0].id }).then((res) => {
                              this.expertList = res.data
                              this.expertList.resTypeName = this.types
                              this.expertList.surveyName = this.editsurveyName || this.form.name
                              if (!this.expertList.achievementsDTO) {
                                this.expertList.achievementsDTO = []
                              }
                              this.getTypesLabel()
                            })
                          } else if (res.data.surveyTypeName == '设计单位' || res.data.surveyTypeName == '海外设计单位')
                          {
                          getCompanyDetails({ id: this.selectedRows[0].id }).then((res) => {
                              this.companyDetList = res.data
                              this.companyDetList.resTypeName = this.types
                              this.companyDetList.surveyName = this.editsurveyName || this.form.name
                              if (!this.companyDetList.achievementsDTO) {
                                this.companyDetList.achievementsDTO = []
                              }
                              if (!this.companyDetList.companyManagements) {
                                this.companyDetList.companyManagements = []
                              }
                              if (!this.companyDetList.certifications) {
                                this.companyDetList.certifications = []
                              }
                              this.getTypesLabel()
                            })
                          }
                        }
                      })
                    }
                }else if(this.isFromRecommand==false){ //自己填的数据

                editBasic(this.form).then((res) => {
                  if ( res.code == 200 ) {
                    this.types = res.data.surveyTypeName
                    this.nextSteps='2'
                    if (this.types == '设计专家' || this.types == '海外设计专家') {
                      getSurveyList({ id: this.id }).then((res) => {
                        this.expertList = res.data
                        this.expertList.resTypeName = this.types
                        this.expertList.surveyName = this.editsurveyName || this.form.name
                        if (!this.expertList.achievementsDTO) {
                          this.expertList.achievementsDTO = []
                        }
                        if(!this.expertList.maxEducationId){
                          this.$set(this.expertList,'maxEducationName','')
                          // 最高学历无placeholder
                          this.$set(this.expertList,'maxEducationId',undefined)
                        }
                        // 职称无placeholder
                        if(!this.expertList.jobTitleId){
                          this.$set(this.expertList,'jobTitleId','')
                        }
                        this.getTypesLabel()
                      })
                    } else if (this.types == '设计单位' || this.types == '海外设计单位') {
                      getCompanyDetailsInvestigate({ id: this.id }).then((res) => {
                        this.companyDetList = res.data
                        this.companyDetList.resTypeName = this.types
                        this.companyDetList.surveyName = this.editsurveyName || this.form.name
                        if (!this.companyDetList.achievementsDTO) {
                          this.companyDetList.achievementsDTO = []
                        }
                        if(!this.companyDetList.natureOfEnterpriseId){
                          this.$set(this.companyDetList,'natureOfEnterpriseId',undefined)
                        }
                        if (!this.companyDetList.companyManagements) {
                          this.companyDetList.companyManagements = []
                        }
                        if (!this.companyDetList.certifications) {
                          this.companyDetList.certifications = []
                        }
                        this.getTypesLabel()
                      })
                    }
                  }
                })
                }
            }
            else { //新增
              this.form.auditStatus = 'DRAFT'
                this.form.memberList = this.memberList
                // 判断是自己选的还是从设计推荐资源选的
                if(this.isFromRecommand==true){ //从设计资源选择
                       //如果是从设计资源推荐选择的，但是又修改了考察类型
                    if(this.recommandDesignTypeId!==this.form.surveyTypeId){
                      this.form.memberList = this.memberList
                        addBasic(this.form).then((res) => {
                            this.types = res.data.surveyTypeName
                            this.id = res.data.id
                            this.nextSteps='2'
                            if (res.code == 200) {
                              this.resList = res.data
                            if (this.types == '设计专家' || this.types == '海外设计专家') {
                              getSurveyList({ id: this.id }).then((res) => {
                                this.expertList = res.data
                                this.expertList.resTypeName = this.types
                                this.expertList.surveyName = this.editsurveyName || this.form.name
                                if (!this.expertList.achievementsDTO) {
                                  this.expertList.achievementsDTO = []
                                }
                                if(!this.expertList.maxEducationId){
                                  this.$set(this.expertList,'maxEducationName','')
                                  // 最高学历无placeholder
                                  this.$set(this.expertList,'maxEducationId',undefined)
                                }
                                // 职称无placeholder
                                if(!this.expertList.jobTitleId){
                                  this.$set(this.expertList,'jobTitleId','')
                                }
                                this.getTypesLabel()
                              })
                            } else if (this.types == '设计单位' || this.types == '海外设计单位') {
                              getCompanyDetailsInvestigate({ id: this.id }).then((res) => {
                                this.companyDetList = res.data
                                this.companyDetList.resTypeName = this.types
                                this.companyDetList.surveyName = this.editsurveyName || this.form.name
                                if (!this.companyDetList.achievementsDTO) {
                                  this.companyDetList.achievementsDTO = []
                                }
                                if(!this.companyDetList.natureOfEnterpriseId){
                                  this.$set(this.companyDetList,'natureOfEnterpriseId',undefined)
                                }
                                if (!this.companyDetList.companyManagements) {
                                  this.companyDetList.companyManagements = []
                                }
                                if (!this.companyDetList.certifications) {
                                  this.companyDetList.certifications = []
                                }
                                this.getTypesLabel()
                              })
                            }
                          }
                        })
                    }else{ //从设计资源选择的未修改考察类型
                      this.form.memberList = this.memberList
                      addBasic(this.form).then((res) => {
                        this.types = res.data.surveyTypeName
                        this.id = res.data.id
                        this.nextSteps='2'
                        if (res.code == 200) {
                          this.resList = res.data
                          if (res.data.surveyTypeName == '设计专家' || res.data.surveyTypeName == '海外设计专家') {
                            getExportDetails({ id: this.selectedRows[0].id }).then((res) => {
                              this.expertList = res.data
                              this.expertList.resTypeName = this.types
                              this.expertList.surveyName = this.editsurveyName || this.form.name

                              if (!this.expertList.achievementsDTO) {
                                this.expertList.achievementsDTO = []
                              }
                              this.getTypesLabel()
                            })
                          } else if (res.data.surveyTypeName == '设计单位' || res.data.surveyTypeName == '海外设计单位')
                          {
                          getCompanyDetails({ id: this.selectedRows[0].id }).then((res) => {
                              this.companyDetList = res.data
                              this.companyDetList.resTypeName = this.types
                              this.companyDetList.surveyName = this.editsurveyName || this.form.name
                              if (!this.companyDetList.achievementsDTO) {
                                this.companyDetList.achievementsDTO = []
                              }
                              if (!this.companyDetList.companyManagements) {
                                this.companyDetList.companyManagements = []
                              }
                              if (!this.companyDetList.certifications) {
                                this.companyDetList.certifications = []
                              }
                              this.getTypesLabel()
                            })
                          }
                        }
                      })
                    }
                }else if(this.isFromRecommand==false){ //自己填的数据
                this.form.memberList = this.memberList
                addBasic(this.form).then((res) => {
                  this.types = res.data.surveyTypeName
                  this.id = res.data.id
                   this.nextSteps='2'
                  if (res.code == 200) {
                    this.resList = res.data
                    if (res.data.surveyTypeName == '设计专家' || res.data.surveyTypeName == '海外设计专家') {
                      getSurveyList({ id: this.id}).then((res) => {
                        this.expertList = res.data
                        this.expertList.resTypeName = this.types
                        this.expertList.surveyName = this.editsurveyName || this.form.name
                        if (!this.expertList.achievementsDTO) {
                          this.expertList.achievementsDTO = []
                        }
                        this.getTypesLabel()
                      })
                    } else if (res.data.surveyTypeName == '设计单位' || res.data.surveyTypeName == '海外设计单位')
                    {
                    getCompanyDetailsInvestigate({ id: this.id }).then((res) => {
                        this.companyDetList = res.data
                        this.companyDetList.resTypeName = this.types
                        this.companyDetList.surveyName = this.editsurveyName || this.form.name
                        if (!this.companyDetList.achievementsDTO) {
                          this.companyDetList.achievementsDTO = []
                        }
                        if (!this.companyDetList.companyManagements) {
                          this.companyDetList.companyManagements = []
                        }
                        if (!this.companyDetList.certifications) {
                          this.companyDetList.certifications = []
                        }
                        this.getTypesLabel()
                      })
                    }
                  }
                })
                }
            }
          }
        }
      }
      if (steps == '2') {
        this.nextSteps = '3'
        this.ifSaveDraft = 2
      }
    },
    handleCancel() {
      let _this = this
      _this.visible = false
      // const formAdd = _this.$refs.createModal.form
      // formAdd.resetFields() // 清理表单数据
    },
    changeMember(value) {
      this.employee = value
      this.formAdd = {
        ...this.formAdd,
        employeeName: value.label,
        employeeId: value.key,
      }
      let list = []
      list = this.groupList.filter((item) => item.id == value.key)
      let jobs = []
      list[0].posts.forEach((item) => {
        jobs.push(item.name)
      })
      this.formAdd.post = jobs.join(',')
      this.$nextTick(() => {
        this.$refs.createModal.validateField('employeeId')
      })
    },
    reduceData(arr) {
      var result = []
      var obj = {}
      for (var i = 0; i < arr.length; i++) {
        if (!obj[arr[i].employeeId]) {
          result.push(arr[i])
          obj[arr[i].employeeId] = true
        }
      }
      return result
    },
    handleEdit(record, index) {
      this.editTargetIndex = index
      this.ifReplace = 1
      this.employee = {
        label: record.employeeName,
        value: record.employeeId,
      }
      this.visible = true
      this.formAdd = { ...record }
      // this.formAdd.post = this.formAdd.post.split(",")
      this.employee = {
        label: record.employeeName,
        value: record.employeeId,
      }
    },
    handleOk() {
      let that = this
      that.$refs.createModal.validate((valid) => {
        if (!valid) {
          this.$message.warning("请填写完所有必填项信息")
          return}

        const targetData = this.memberList[this.editTargetIndex] || null // 当前操作的目标对象
        const isLeader = targetData && targetData.leader === '1' // 当前操作目标对象是否为组长

        // 校验人员是否存在于小组
        if (
          that.memberList.some((item) => {
            if (targetData) {
              // 如果targetData存在，则需绕过targetData.employeeId代表的人（目的是，在编辑验重时，将原数据的人员排除在外）
              return targetData.employeeId !== that.formAdd.employeeId && item.employeeId === that.formAdd.employeeId
            }
            return item.employeeId === that.formAdd.employeeId
          })
        ) {
          that.$message.warning('此人员已存在于小组！')
          return
        }
        // 验证是否有组长（如果目标对象是组长，则无需校验；如果目标对象不是组长，则查询列表中是否已经存在组长）
        if (!isLeader) {
          const leaderIndex = that.memberList.findIndex((item) => item.leader === '1')
          if (leaderIndex > -1 && that.formAdd.leader === '1') {
            that.$message.warning('只能选择一个考察小组组长')
            return
          }
        }
        that.visible = false
        // 设计资源考察编辑

        if (that.id) {
          if (that.ifReplace == 1) {
            that.memberList.splice(that.editTargetIndex, 1, { ...that.formAdd })
            that.editTargetIndex = null
          } else {
            that.memberList.push(that.formAdd)
            let newMembers = that.reduceData(that.memberList)
            that.memberList = newMembers
          }
        } else {
          // 设计考察新增
          if (that.ifReplace == 1) {
            that.memberList.splice(that.editTargetIndex, 1, { ...that.formAdd })
            that.editTargetIndex = null
          } else {
            let arrys = []
            arrys = that.memberList.concat(that.formAdd)

            that.memberList = that.reduceData(arrys)
          }
        }
      })
    },
    handleOkSelect() {
      const row = this.selectedRows[0]
      if (!row) return
      getDesignResourcesList({pageNo:1,pageSize:2000}).then(res=>{
        let data=[]
        data=res.data.filter(item=>item.name==row.resName)
        if(data.length>=1){
          this.$message.error("此设计资源推荐已入库")
          return false
        }else{
          this.selectVisible = false
          this.form = {
            ...this.form,
            name: row.resName,
            surveyTypeId: row.resTypeId,
            surveyLevelId: row.resLevelId,
            // branchComId: row.recommendOrgId,
            recommandId: row.id,
          }
          this.recommandDesignTypeId=row.resTypeId
          this.recommandDesignTypeName=row.resTypeName
          this.isFromRecommand=true
          this.$nextTick(() => {
            this.$refs.ruleForm.validateField(['name', 'surveyTypeId', 'surveyLevelId', 'recommandId'])
          })
        }
      })
    },
  },
}
</script>

<style lang="less" scoped>
.wrapper-row {
  padding-left: 55px;
  font-weight: bold;
  letter-spacing: 1px;
}

/deep/ .ant-form-item label {
  font-size: 12px;
}

/deep/ .ant-btn {
  border-radius: 5px;
}

/deep/ .ant-calendar-picker-input.ant-input {
  width: 100%;
}

/deep/ .ant-input {
  /*width: 70%;*/
  border-radius: 5px;
}

/deep/ .ant-card.ant-card-bordered {
  border-radius: 5px;
}

.ant-avatar-lg {
  width: 48px;
  height: 48px;
  line-height: 48px;
}

.list-content-item {
  color: rgba(0, 0, 0, 0.45);
  display: inline-block;
  vertical-align: middle;
  font-size: 14px;
  margin-left: 40px;
  span {
    line-height: 20px;
  }
  p {
    margin-top: 4px;
    margin-bottom: 0;
    line-height: 22px;
  }
}

.title-name {
  border-left: 5px solid #1890ff;
  font-weight: bold;
  font-size: 16px;
  margin-bottom: 20px;
  padding-left: 15px;
  height: 20px;
  line-height: 20px;
}

/deep/ .table-page-search-wrapper .ant-form-inline .ant-row .ant-col.ant-col-sm-24.ant-col-md-12 {
  padding-left: 80px;
}
/*/deep/ .ant-layout, .ant-layout{*/
/*  padding:0*/
/*}*/
.button {
  margin: 30px 10px 0 10px;
}
/deep/ .ant-table-pagination.ant-pagination {
  display: none;
}
</style>
